package com.huanletao.threadPool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class App {

    public static void main(String[] args) {

    }


    AtomicInteger atomicInteger = new AtomicInteger();

    private int index;

    public void increase() throws InterruptedException {
        new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                index = atomicInteger.incrementAndGet();
            }
        }).start();

        new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                index = atomicInteger.incrementAndGet();
            }
        }).start();

        Thread.sleep(1000);
        System.out.println("-----" + index); // 输出结果20000
    }

    public static void testContinue() {
        retry:
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 5; j++) {
                System.out.print(j + ", ");
                if(j == 3) {
                    continue retry;
                }
            }
        }
        System.out.print(" >>> OK");
    }
// 输出：0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,  >>> OK


    public static void testBreak() {
        retry:
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 5; j++) {
                System.out.print(j + ", ");
                if(j == 3) {
                    break retry;
                }
            }
        }
        System.out.print(" >>> OK");
    }
// 输出：0, 1, 2, 3,  >>> OK

    private static void extracted() {
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5, 10, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10));

        threadPool.execute(() -> {
            throw new RuntimeException();
        });
        threadPool.shutdownNow();
    }
}
